home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / myPlatform ƒ / sPlatform.p < prev    next >
Encoding:
Text File  |  1993-09-19  |  3.0 KB  |  120 lines  |  [TEXT/PJMM]

  1. { Platform sprite, experimental faceless sprite }
  2.  
  3. unit sPlatform;
  4.  
  5. interface
  6.  
  7.     uses
  8.         SAT;
  9.  
  10.     procedure InitPlatform;
  11.     procedure SetupPlatform (me: SpritePtr);
  12.     procedure HandlePlatform (me: SpritePtr);
  13.     procedure HitPlatform (me, him: SpritePtr);
  14.  
  15. implementation
  16.  
  17.     procedure InitPlatform;
  18.         var
  19.             i: integer;
  20.     begin
  21. {The platform has no faces!}
  22.     end;
  23.  
  24.     procedure SetupPlatform (me: SpritePtr);
  25.         var
  26.             r: Rect;
  27.             pol: PolyHandle;
  28.     begin
  29.         {me^.kind := -2; {Enemy kind}
  30.         me^.face := nil; {=faceless!}
  31.         SetRect(me^.hotRect, 0, 0, 100, 16);
  32.         r := me^.hotRect;
  33.         offSetRect(r, me^.position.h, me^.position.v);
  34.         SetPort(BackScreen);
  35. {Perhaps we should SATSetPortBackScreen nowadays…}
  36. {but it works anyway - we're in no hurry here, and we don't CopyBits.}
  37.         FillRect(r, dkgray);
  38.  
  39.         pol := OpenPoly;
  40.         MoveTo(r.left, r.top);
  41.         LineTo(r.left + 5, r.top - 5);
  42.         LineTo(r.right + 5, r.top - 5);
  43.         LineTo(r.right, r.top);
  44.         LineTo(r.left, r.top);
  45.         LineTo(r.right, r.top);
  46.  
  47.         LineTo(r.right, r.bottom);
  48.         LineTo(r.right + 5, r.bottom - 5);
  49.         LineTo(r.right + 5, r.top - 5);
  50.         LineTo(r.right, r.top);
  51.  
  52.         ClosePoly;
  53.         ErasePoly(pol);
  54.         FramePoly(pol);
  55.         KillPoly(pol);
  56.  
  57.         r.top := r.top - 5;
  58.         r.right := r.right + 5;
  59.         SATBackChanged(r); {Tell SAT to draw it when appropriate}
  60.  
  61.         me^.layer := -me^.position.v;
  62.     end;
  63.  
  64.     procedure HandlePlatform (me: SpritePtr);
  65.     begin
  66.         {me^.face := nil; {Really not needed}
  67.     end;
  68.  
  69.     procedure HitPlatform;
  70.         var
  71.             mini, i, min: integer;
  72.             diff: array[1..4] of integer;
  73.     begin
  74.         if him^.Task <> @HandlePlatform then
  75.             begin
  76.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);    {TtoB}
  77.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);    {BtoT}
  78.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);    {LtoR}
  79.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);    {RtoL}
  80.                 mini := 0;
  81.                 min := 10000;
  82.                 for i := 1 to 4 do
  83.                     if min > diff[i] then
  84.                         begin
  85.                             min := diff[i];
  86.                             mini := i;
  87.                         end;
  88.                 case mini of
  89.                     1: {floor}
  90.                         begin
  91.                             him^.position.v := him^.position.v - diff[1] + 1;
  92.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  93.                             if him^.speed.v > 0 then
  94.                                 him^.speed.v := 0;
  95.                         end;
  96.                     2: {ceiling}
  97.                         begin
  98.                             him^.position.v := him^.position.v + diff[2] + 1;{me^.position.v + 17}
  99. {We don't signal here. A hit in the ceiling should just send him back down again.}
  100.                             if him^.speed.v < 0 then
  101.                                 him^.speed.v := -him^.speed.v;
  102.                         end;
  103.                     3: {left}
  104.                         begin
  105.                             him^.position.h := him^.position.h - diff[3] - 1;{me^.position.h - 32}
  106.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  107.                             if him^.speed.h > 0 then
  108.                                 him^.speed.h := -him^.speed.h;
  109.                         end;
  110.                     4: {right}
  111.                         begin
  112.                             him^.position.h := him^.position.h + diff[4] + 1;{me^.position.h + 100}
  113.                             him^.kind := 10; {Signal to him, as if we used KindCollision}
  114.                             if him^.speed.h < 0 then
  115.                                 him^.speed.h := -him^.speed.h;
  116.                         end;
  117.                 end;{case}
  118.             end; {if}
  119.     end; {HitPlatform}
  120. end.{of unit}